import book.Library;
import user.AdminUser;
import user.NormalUser;
import user.ProxyUser;
import user.User;
import user.factory.AdminUserFactory;
import user.factory.IUserFactory;
import user.factory.NormalUserFactory;
import utils.ScannerSingleton;

import java.io.IOException;
import java.util.Scanner;

public class LibrarySystem {
    public static void main(String[] args) throws IOException {

        //我们在这里需要频繁的创建对象，其实可以引入工厂模式，将对象的创建与使用分开，达到解耦的目的
//        User admin = new AdminUser("刘备",1);
//
//        User normal1 = new NormalUser("张飞",2);
//        User normal2 = new NormalUser("关羽",3);
//
//        admin.display();
//        normal1.display();
//        normal2.display();
        IUserFactory adminUserFactory = new AdminUserFactory();
        User adminUser = adminUserFactory.createUser("刘备" , 1);

        IUserFactory normalUserFactory = new NormalUserFactory();
        User normalUser1 = normalUserFactory.createUser("关羽",2);
        User normalUser2 = normalUserFactory.createUser("张飞",3);

//        adminUser.display();

        ProxyUser proxyAdminUser = new ProxyUser(adminUser);
        ProxyUser proxyNormalUser1 = new ProxyUser(normalUser1);
        ProxyUser proxyNormalUser2 = new ProxyUser(normalUser2);


        LibrarySystem librarySystem = new LibrarySystem();

        ProxyUser currentUser = librarySystem.selectProxRole(proxyAdminUser,proxyNormalUser1,proxyNormalUser2);


        while(true){
            int choice = currentUser.display();
            currentUser.handleOperation(choice);
            //如何实现输入什么就执行哪个用户的操作
        }

    }

    public ProxyUser selectProxRole(ProxyUser proxyUserAdmin,ProxyUser proxyUserNormal1 , ProxyUser proxyUserNormal2){
        System.out.println("选择⻆⾊进⾏登录：");
        System.out.println("1.管理员\n2.普通⽤⼾(关⽻)\n3.普通⽤⼾(张⻜)\n4.退出系统");
        ProxyUser currentUser = null;

        Scanner scanner = ScannerSingleton.getInstance();

        int choice = scanner.nextInt();
        switch (choice){
            case 1:
                currentUser = proxyUserAdmin;
                break;
            case 2:
                currentUser = proxyUserNormal1;
                break;
            case 3:
                currentUser = proxyUserNormal2;
                break;
            case 4:
                System.exit(0);
                System.out.println("系统已经退出");
                break;
            default:
                break;
        }
        return currentUser;
    }
}
